package com.ptp.backendcertms.basiccompnents.data.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ptp.backendcertms.basiccompnents.data.dao.entity.OrgPo;
import com.ptp.backendcertms.basiccompnents.data.dao.mapper.IOrgMapper;
import com.ptp.backendcertms.basiccompnents.data.dao.service.IOrgService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

import static com.ptp.backendcertms.api.internal.constant.DateTypeConstant.DATE_TIME_PATTERN_SHORT_MATTER;

/**
 * 机构模型 服务实现
 *
 * @author songcongcong
 * @date 2025/5/1
 */
@Service
public class OrgServiceImpl extends ServiceImpl<IOrgMapper, OrgPo> implements IOrgService {

    @Override
    public void saveOrUpdateOrgInfo(OrgPo entity) {
        if (Objects.isNull(entity.getId())) {
            entity.setCreateTime(LocalDateTime.now().format(DATE_TIME_PATTERN_SHORT_MATTER));
            save(entity);
        }
        updateById(entity);
    }

    @Override
    public List<OrgPo> queryListByIdList(List<Long> idList) {
        LambdaQueryWrapper<OrgPo> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.in(OrgPo::getId, idList);
        return list(lambdaQueryWrapper);
    }
}
